package com.company.ThreadDemo;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class LockDemo {
    public static void main(String[] args) {
        Monney monney = new Monney();
        new Thread(()->{
            for (int i = 0; i < 70; i++) {
                monney.quqian();
            }
        },"a").start();
        new Thread(()->{
            for (int i = 0; i < 70; i++) {
                monney.quqian();
            }
        },"b").start();
    }
}
class Monney{
    int num = 100;
    Lock lock = new ReentrantLock();

    public  void quqian(){
        lock.lock();
        
        if(num>0) {
            System.out.println(Thread.currentThread().getName() + num-- + "取钱成功");
        }
        lock.unlock();
    }
}
